import 'package:dk_flutter_base/dk_core.dart';
import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/phoenix/tools/bean/bean_tools_item.dart';
import 'package:dk_flutter_module_sale/r.dart';

typedef ItemTapCallback = void Function(
    ToolsItem item, editStatusType type); //没有编辑状态，点击是跳转，编辑状态，点击是对应的增加和减少

enum editStatusType {
  editStatusTypeNone, //默认没有编辑状态
  editStatusTypeSub, //减号状态
  editStatusTypeAdd, //加号状态
}

class EditToolItemWidget extends StatelessWidget {
  final ToolsItem item;
  final editStatusType editType;
  final ItemTapCallback tapCallback;
  EditToolItemWidget(this.item,
      {this.editType = editStatusType.editStatusTypeNone, this.tapCallback});
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        tapCallback(item, editType);
      },
      child: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              width: 52,
              child: Stack(
                alignment: AlignmentDirectional.center,
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.only(top: 4),
                    child: ClipOval(
                        child: CachedNetworkImage(
                      imageUrl: item.iconUrl ?? "",
                      fit: BoxFit.cover,
                      height: 43,
                      width: 43,
                       placeholder: (context, url) {
                          return Image.asset(R.imagesToolsToolIconPalceholderPng,
                              height: 43, width: 43, fit: BoxFit.cover);
                        },
                      errorWidget: (context, url,error) {
                      return Image.asset(R.imagesToolsToolIconPalceholderPng,
                          height: 43,
                          width: 43,
                          fit: BoxFit.cover);
                    }
                    )),
                  ),
                  Positioned(
                    left: 34,
                    top: 0,
                    child: _getIcon(),
                  )
                ],
              ),
            ),
          
            Padding(
              padding: EdgeInsets.only(top: 7),
              child: DkText.simple( item.title??"", 13, Color(0xff666666),fontWeight: FontWeight.normal,),
            ),
           
          ],
        ),
      ),
    );
  }

  Widget _getIcon() {
    if (editType == editStatusType.editStatusTypeAdd) {
      return Image.asset(R.imagesToolsToolAddPng,
        width: 17,
        height: 17,
        fit: BoxFit.fill,
      );
    } else if (editType == editStatusType.editStatusTypeSub) {
      return Image.asset(R.imagesToolsToolDeletePng,
        width: 17,
        height: 17,
        fit: BoxFit.fill,
      );
    } else {
      return SizedBox();
    }
  }
}

class ToolsModuleTitle extends StatelessWidget {
  final String leftTitle;
  final String rightNum;
  const ToolsModuleTitle(this.leftTitle, {this.rightNum = "", Key key})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
        padding: EdgeInsets.symmetric(horizontal: 16),
        height: 50,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Expanded(
              child: DkText.simple(leftTitle, 18, Color(0xff333333)),
            ),
            rightNum.length > 0
                ? Text.rich(TextSpan(children: <TextSpan>[
                    TextSpan(
                        text: rightNum,
                        style:
                            TextStyle(color: Color(0xff3274F9), fontSize: 16)),
                    TextSpan(
                        text: "/8",
                        style:
                            TextStyle(color: Color(0xff3F3F3F), fontSize: 16))
                  ]))
                : SizedBox(),
          ],
        ));
  }
}
